#include <set>
#include <iostream>
#include <vector>

void mergeSets(std::vector<std::set<char>> &equal_set, std::set<char> &ts)
{
    std::vector<int> merge_idx;
    std::vector<std::set<char>> merge_set;
    for (int i = 0; i < equal_set.size(); i++)
    {
        bool find = false;
        for (auto it = ts.begin(); it != ts.end(); it++)
        {
            if (equal_set[i].count(*it) > 0)
            {
                merge_idx.push_back(i);
                find = true;
                break;
            }
        }
        if (!find)
        {
            merge_set.push_back(equal_set[i]);
        }
    }

    std::set<char> mset = ts;
    for (int i = 0; i < merge_idx.size(); i++)
    {
        std::set<char> tmpset = equal_set[merge_idx[i]];
        for (auto it = tmpset.begin(); it != tmpset.end(); it++)
        {
            mset.insert(*it);
        }
    }
    merge_set.push_back(mset);

    equal_set.swap(merge_set);
}

int main()
{
    std::string istr;
    std::cin >> istr;

    std::vector<std::set<char>> equal_set;
    std::string mstr;
    int i = 0;
    while (i < istr.size())
    {
        if (istr[i] == '(')
        {
            i++;
            std::set<char> ts;
            while (istr[i] != ')')
            {
                ts.insert(std::tolower(istr[i]));
                i++;
            }
            mergeSets(equal_set, ts);
            i++;
        }
        else
        {
            mstr.push_back(std::tolower(istr[i]));
            i++;
        }
    }

    for (int i = 0; i < mstr.size(); i++)
    {
        for (int j = 0; j < equal_set.size(); j++)
        {
            if (equal_set[j].count(mstr[i]))
            {
                mstr[i] = *equal_set[j].begin();
                break;
            }
        }
    }
    if (mstr.size() == 0)
        std::cout << 0 << std::endl;
    else
        std::cout << mstr << std::endl;

    return 0;
}